|
|
|
|
|
|
|
Throughout the process of communicating with the ODBC interface, you need to check for any error codes returned by ODBC. Because the functions are executing outside your Visual Basic program, ODBC errors do not automatically invoke your Visual Basic error handler. Every major ODBC call returns a success code or an error code. After you execute an ODBC API call, you need to check the return code. If it indicates that an error occurred, you also can call an ODBC routine that returns the detailed error message generated by the data source. When you build your ODBC library, you write a routine to perform this error checking. |
|
|
|
|
|
|
|
|
The first thing you need to do to build your library is to declare the necessary API calls for the ODBC interface. In your project, you declare only a subset of the total ODBC API calls; these are the calls essential for creating a basic data-entry form. You also need a handful of Visual Basic constants that you use throughout the library. |
|
|
|
|
|
|
|
|
Load Visual Basic 5 and start a new ActiveX project. Add a BAS module to the project and set its Name property to modODBC. Add the API calls in Listing 19.1 to the project. |
|
|
|
|
| |
|
|
|
|
If you want to save yourself some typing (and possible typing errors), you can find the MODODBC.BAS file in the C:\TYSDBVB5\SOURCE\ CHAP19\PRJODBC directory on the CD. You can load this file into your project by choosing Project | Add File. |
|
|
|
|
|
|
|
|
|
|
Listing 19.1. The ODBC API declarations. |
|
|
|
|
|
|
|
|
Option Explicit
' ----------------------------------------------------------
' ODBC API Declarations
' ----------------------------------------------------------
'
' basic ODBC Declares
Declare Function SQLAllocEnv Lib "odbc32.dll" (env As Long) As Integer
Declare Function SQLFreeEnv Lib "odbc32.dll" (ByVal env As Long) As Integer
Declare Function SQLAllocConnect Lib "odbc32.dll" (ByVal env As Long, _
hDbc As Long) As Integer
Declare Function SQLConnect Lib "odbc32.dll" (ByVal hDbc As Long, _
ByVal Server As String, ByVal serverlen As Integer, _ |
|
|
|
|
|